<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*,cn.jingsheng.backup.bean.*,cn.jingsheng.backup.util.*,cn.jingsheng.backup.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户管理</title>
<script type="text/javascript">
	function changeRoleId(cb,username,role){
		var roleId = document.getElementById("id_"+username);
		if(cb.checked){
			roleId.value=Number(roleId.value) + role*1;
		}else{
			roleId.value=Number(roleId.value) - role*1;
		}
	}
	function deleteuser(username){
		if(confirm("确认删除用户 ["+username+"] ?")){
			window.location.href="BackupServlet?cmd=deleteuser&username="+username;
		}
	}
	function adduser(){
		
		if(document.adduserForm.username.value==""){
			alert("账户不能为空!");
			return false;
		}
		if(document.adduserForm.password.value==''){
			alert("密码不能为空!");
			return false;
		}
		if(document.adduserForm.retrypassword.value!=document.adduserForm.password.value){
			alert("两次输入密码不一致!");
			return false;
		}
		document.adduserForm.btnsubmit.disabled="disabled";
		return true;
	}
</script>
</head>
<body>
<p align="center" style="font-size: 24px;">竞盛公司业务文档电子报备系统---用户管理</p>
<form action="BackupServlet?cmd=changerole" method="post" >
	<table border="1" align="center">
	<caption>权限管理</caption>
		<tr>
			<td >账户</td>
			<td>查看</td>
			<td>删除</td>
			<td>下载</td>
			<td>上传</td>
			<td >&nbsp;</td>
		</tr>
    <%List<UserLogin> userList =(List<UserLogin>)request.getAttribute("userList");
    	for(int i=0;i!=userList.size();i++){
    		UserLogin user = userList.get(i);
    %>
		<tr>
			<td><%=user.getUserName() %>
			<input type="hidden" name="username" value="<%=user.getUserName() %>"/>
			<input type="hidden" name="roleId" id="id_<%=user.getUserName() %>" value="<%=user.getRoleId() %>"/>
			</td>
			<td><input type="checkbox" onchange="changeRoleId(this,'<%=user.getUserName() %>',<%=Constants.ROLE_VIEW %>)" <%=user.canView()?"checked='checked'":"" %> <%="admin".equals(user.getUserName())?"disabled='disabled'":"" %>/></td>
			<td><input type="checkbox" onchange="changeRoleId(this,'<%=user.getUserName() %>',<%=Constants.ROLE_DELETE %>)" <%=user.canDelete()?"checked='checked'":"" %> <%="admin".equals(user.getUserName())?"disabled='disabled'":"" %>/></td>
			<td><input type="checkbox" onchange="changeRoleId(this,'<%=user.getUserName() %>',<%=Constants.ROLE_DOWN %>)" <%=user.canDownload()?"checked='checked'":"" %> <%="admin".equals(user.getUserName())?"disabled='disabled'":"" %>/></td>
			<td><input type="checkbox" onchange="changeRoleId(this,'<%=user.getUserName() %>',<%=Constants.ROLE_UPLOAD %>)" <%=user.canUpload()?"checked='checked'":"" %> <%="admin".equals(user.getUserName())?"disabled='disabled'":"" %>/></td>
			<td><%if(!"admin".equals(user.getUserName())){ %><a href="#" onclick="deleteuser('<%=user.getUserName() %>');">删除</a><%} %>&nbsp;</td>
		</tr>
		<%} %>
		<tr>
			<td colspan="6" align="center">
				<input type="submit" value="修改"/>
				<input type="button" value="关闭" onclick="window.close();"/>
			</td>
		</tr>
	</table>
</form>
<br/>
<hr/>
<form name="adduserForm" action="BackupServlet?cmd=adduser" method="post" onsubmit="return adduser();">
<table border="1" align="center">
<caption>新增用户</caption>
<tr>
	<td>用户名</td>
	<td><input type="text" name="username" /></td>
</tr>
<tr>
	<td>密&nbsp;码</td>
	<td><input type="password" name="password" /></td>
</tr>
<tr>
	<td>确认密码</td>
	<td><input type="password" name="retrypassword" /></td>
</tr>
<tr>
	<td colspan="2" align="center"><input type="submit" name="btnsubmit" value="新增用户"/></td>
</tr>
</table>
</form>
</body>
</html>